package com.zhkjnet.zhyy.bean;

import java.util.ArrayList;
import java.util.List;

public class Paging {

    /**
     * 当前页数
     */
    private long page;

    /**
     * 数量
     */
    private long count;

    /**
     * 页长度
     */
    private int length;

    /**
     * 总页数
     */
    private long all;

    /**
     * 展示的页数
     */
    private List<Long> shows;

    /**
     * 展示长度
     */
    private int showLength;

    public Paging(long page, int length, long count, int showLength) {
        this.page = page;
        this.length = length;
        this.count = count;
        this.showLength = showLength;
        this.init();
    }

    public long getPage() {
        return page;
    }

    public void setPage(long page) {
        this.page = page;
    }

    public long getCount() {
        return count;
    }

    public void setCount(long count) {
        this.count = count;
    }

    public int getLength() {
        return length;
    }

    public void setLength(int length) {
        this.length = length;
    }

    public long getAll() {
        return all;
    }

    public void setAll(long all) {
        this.all = all;
    }

    public List<Long> getShows() {
        return shows;
    }

    public void setShows(List<Long> shows) {
        this.shows = shows;
    }

    public int getShowLength() {
        return showLength;
    }

    public void setShowLength(int showLength) {
        this.showLength = showLength;
    }

    private void init() {
        shows = new ArrayList<>();
        all = (count / length) + 1;
        if (all <= showLength) {
            //总页数小于当前需要展示的页数
            for (long i = 1; i <= all; i ++) {
                shows.add(i);
            }
        } else if (page + showLength > all) {
            //当前页数在尾部
            for (int i = 0; i < showLength; i ++) {
                shows.add(all - showLength + i);
            }
        } else {
            //正常情况
            for (int i = 0; i < showLength; i ++) {
                //放到中间
                shows.add(page - (showLength) / 2 + i);
            }
        }
    }
}
